<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition>
	<h:outputText
		value="System error:purchaseInfoInputPanel: purchase model current is null"
		rendered="#{purchaseModel.current == null}"></h:outputText>

	<h:panelGrid columns="1" style="width:100%">
		<h:panelGrid columns="1" style="width:100%">
			<h:panelGrid columns="2" style="width:100%">
				<h:outputText value="id" />
				<h:outputText value="#{purchaseModel.current.id}" />
				<h:outputText value="Supplier"></h:outputText>
				<h:panelGrid columns="3" style="float:left;width:100%">
					<h:outputText value="#{purchaseModel.current.supplier.name}" />
					<p:commandButton actionListener="#{supplierController.init}"
						ajax="true" update=":dialogForm,:headerForm" value="Choose"
						oncomplete="supplierDlg.show()"></p:commandButton>
				</h:panelGrid>
				<h:outputText value="Number" />
				<h:outputText value="#{purchaseModel.current.number}" />
				<h:outputText value="Status" />
				<h:outputText value="#{purchaseModel.current.status}" />
				<h:outputText value="Paid amount" />
				<h:outputText value="#{purchaseModel.current.paidAmount}" />
				<h:outputText value="Discount amount" />
				<h:outputText value="#{purchaseModel.current.discountAmount}" />
				<h:outputText value="Comments" />
				<h:inputTextarea value="#{purchaseModel.current.comments}" />
			</h:panelGrid>
			<p:panelGrid style="width:100%">
				<p:row>
					<p:column rowspan="6">Date</p:column>
					<p:column rowspan="1">Purchased</p:column>
					<p:column rowspan="1">
						<h:outputText value="#{purchaseModel.current.purchasedDate}" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>Required</p:column>
					<p:column>
						<p:calendar value="#{purchaseModel.current.requiredDate}" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>Confirmed</p:column>
					<p:column>
						<h:outputText value="#{purchaseModel.current.confirmedDate}" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>Received</p:column>
					<p:column>
						<h:outputText value="#{purchaseModel.current.receivedDate}" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>Paid</p:column>
					<p:column>
						<h:outputText value="#{purchaseModel.current.paidDate}" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>Canceled</p:column>
					<p:column>
						<h:outputText value="#{purchaseModel.current.canceledDate}" />
					</p:column>
				</p:row>
			</p:panelGrid>
		</h:panelGrid>

		<p:separator />
		<h:panelGrid columns="2" style="width:100%">
			<p:commandButton oncomplete="productDlg.show()" ajax="true"
				update=":dialogForm" actionListener="#{productController.init}"
				icon="add" value="Add" title="Add products" style="float:left"></p:commandButton>
			<p:commandButton ajax="true" update=":detailForm"
				actionListener="#{purchaseModel.current.purchasedToReceived}"
				value="Purchased to Received" style="float:right"
				disabled="#{!purchaseModel.current.canCancel}"></p:commandButton>
		</h:panelGrid>

		<p:dataTable id="purchaseDetailListTable" var="detail" sortBy="1"
			value="#{purchaseModel.current.purchaseDetails}" rows="20">
			<f:facet name="header">Purchase Items</f:facet>
			<p:columnGroup type="header">
				<p:row>
					<p:column rowspan="2" headerText="" />
					<p:column rowspan="2" headerText="" />
					<p:column rowspan="1" colspan="4" headerText="Product"></p:column>
					<p:column rowspan="1" colspan="3" headerText="Purchased"
						style="max-width:120px" />
					<p:column rowspan="1" colspan="3" headerText="Received"
						style="max-width:120px" />
				</p:row>
				<p:row>
					<p:column rowspan="1" headerText="Number" />
					<p:column rowspan="1" headerText="Name" />
					<p:column rowspan="1" headerText="Inventory" />
					<p:column rowspan="1" headerText="Price" />
					<p:column rowspan="1" headerText="Quantity" />
					<p:column rowspan="1" headerText="Subtotal" />
					<p:column rowspan="1" headerText="Price" />
					<p:column rowspan="1" headerText="Quantity" />
					<p:column rowspan="1" headerText="Subtotal" />
				</p:row>
			</p:columnGroup>

			<p:column style="width:20px">
				<p:commandButton icon="edit" ajax="true"
					oncomplete="purchaseDetailDlg.show()" update=":dialogForm"
					disabled="#{!purchaseModel.current.canCancel}">
					<f:setPropertyActionListener value="#{detail}"
						target="#{purchaseModel.currentPurchaseDetail}" />
				</p:commandButton>
			</p:column>
			<p:column headerText="" style="width:20px">
				<p:commandButton icon="delete" ajax="true" update=":detailForm"
					actionListener="#{purchaseController.removeDetailFromCurrent}"
					disabled="#{!purchaseModel.current.canCancel}">
					<f:setPropertyActionListener value="#{detail}"
						target="#{purchaseController.removeDetailFromCurrent}" />
				</p:commandButton>
			</p:column>

			<p:column>
				<h:outputText value="#{detail.product.number}" />
			</p:column>
			<p:column>
				<h:outputText value="#{detail.product.name}" />
			</p:column>
			<p:column>
				<h:outputText
					value="#{detail.product.inventory} #{detail.product.priceUnit}" />
			</p:column>
			<p:column>
				<h:outputText value="#{detail.purchasedPrice}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText
					value="#{detail.purchasedQuantity} #{detail.product.purchaseUnit}" />
			</p:column>
			<p:column>
				<h:outputText value="#{detail.purchasedSubTotal}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText value="#{detail.receivedPrice}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
				</h:outputText>
			</p:column>
			<p:column>
				<h:outputText
					value="#{detail.receivedQuantity} #{detail.product.purchaseUnit}" />
			</p:column>
			<p:column>
				<h:outputText value="#{detail.receivedSubTotal}">
					<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
				</h:outputText>
			</p:column>

			<p:summaryRow>
				<p:column colspan="5" style="text-align:right">
					<h:outputText value="Total:"></h:outputText>
				</p:column>

				<p:column colspan="2" style="text-align:right">
					<h:outputText
						value="#{purchaseModel.current.purchasedTotalQuantity}" />
				</p:column>
				<p:column>
					<h:outputText value="#{purchaseModel.current.purchasedTotalAmount}"
						style="text-align:right">
						<f:convertNumber minFractionDigits="2" maxFractionDigits="2"></f:convertNumber>
					</h:outputText>
				</p:column>
				<p:column colspan="2" style="text-align:right">
					<h:outputText
						value="#{purchaseModel.current.receivedTotalQuantity}" />
				</p:column>
				<p:column>
					<h:outputText value="#{purchaseModel.current.receivedTotalAmount}"
						style="text-align:right"></h:outputText>
				</p:column>
			</p:summaryRow>
		</p:dataTable>

		<h:panelGrid columns="3">
			<p:splitButton icon="add" value="New" ajax="true"
				update=":listForm,:detailForm,:headerForm">
				<f:setPropertyActionListener value="#{purchaseModel.newObject}"
					target="#{purchaseModel.current}" />
				<p:menuitem value="Pay-Direct" onclick="payDlg.show()"
					disabled="#{!orderModel.current.canPay}" />
				<p:menuitem value="Cancel" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.cancelCurrent}"
					disabled="#{!purchaseModel.current.canCancel}" />
				<p:menuitem value="Pay" onclick="payDlg.show()"
					disabled="#{!purchaseModel.current.canPay}" />
				<p:menuitem value="Process" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.processCurrent}"
					disabled="#{!purchaseModel.current.canProcess}" />
				<p:menuitem value="Receive" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.receiveCurrent}"
					disabled="#{!purchaseModel.current.canReceive}" />
				<p:menuitem value="Confirm" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.confirmCurrent}"
					disabled="#{!purchaseModel.current.canConfirm}" />
				<p:menuitem value="Save" ajax="true" icon="save"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.saveCurrent}"
					disabled="#{!purchaseModel.current.canSave}" />
			</p:splitButton>

			<p:splitButton value="Refresh" ajax="true"
				update=":listForm,:detailForm"
				actionListener="#{purchaseController.refreshCurrent}">
				<p:menuitem value="Restore" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{orderController.restoreCurrent}"
					disabled="#{!orderModel.current.canRestore}" />
				<p:menuitem value="Unpay" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{orderController.unPickupCurrent}"
					disabled="#{!orderModel.current.canUnpickup}" />
				<p:menuitem value="UnProcess" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.unProcessCurrent}"
					disabled="#{!purchaseModel.current.canPay}" />
				<p:menuitem value="Unreceive" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.unReceiveCurrent}"
					disabled="#{!purchaseModel.current.canProcess}" />
				<p:menuitem value="Unconfirm" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{purchaseController.unConfirmCurrent}"
					disabled="#{!purchaseModel.current.canReceive}" />
				<p:menuitem value="delete" icon="delete" ajax="true"
					update=":dialogForm" oncomplete="deleteDlg.show()" />
			</p:splitButton>
			<p:commandButton value="Print"></p:commandButton>
		</h:panelGrid>
	</h:panelGrid>
</ui:composition>
</html>